var testCaseDivision = new YAHOO.tool.TestCase({
  name: "Generation of division problems",
  setUp : function () {
      this.divisionBy3 = new ArithmeticProblemType(
        "DivisionOf3",
        "Division Of 3",
        1,
        [ null,{lb:0,ub:30},{lb:3,ub:3}], 
        [ OperatorEL.dividedBy],
        0       // askedFor = "result"
        );
      this.basicDivision = new ArithmeticProblemType(
          "basic division",
          "basic division",
          1,
          [ null,{lb:0,ub:100},{lb:1,ub:10}], 
          [ OperatorEL.dividedBy],
          0       // askedFor = "result"
        );
      this.timesDividedBy = new ArithmeticProblemType(
          "Multiplication and division",
          "Multiplication and division",
          1,
          [ null,{lb:0,ub:10},{lb:0,ub:10},{lb:0,ub:10}],  
          [ OperatorEL.times, OperatorEL.dividedBy],
          0       // askedFor = "result"
        );
      this.division200 = new ArithmeticProblemType(
          "Division200",
          "Division from up to 200",
          1,
          [ {lb:2,ub:10},{lb:4,ub:200},{lb:10,ub:20}], 
          [ OperatorEL.dividedBy],
          0       // askedFor = "result"
          );
  },
  tearDown : function () {
      delete this.divisionBy3;
      delete this.basicDivision;
      delete this.timesDividedBy;
      delete this.division200;
  },

  testDivisionBy3: function () {
    var Assert = YAHOO.util.Assert;
    var ap = null, xD, yD;
    for (var i=1; i<4; i++) {
      ap = this.divisionBy3.generateProblem();
      xD = ap.operands[0];
      yD = ap.operands[1];
      Assert.isTrue( ap.type.numberRanges[1].lb <= xD &&
        xD <= ap.type.numberRanges[1].ub, "xD = "+ xD +" should be in number range.");
      Assert.isTrue( ap.type.numberRanges[2].lb <= yD &&
        yD <= ap.type.numberRanges[2].ub, "yD = "+ yD +" should be in number range.");
      Assert.areSame( ap.result, xD / yD);      
    }
  },
  testBasicDivision: function () {
    var Assert = YAHOO.util.Assert;
    var ap = this.basicDivision.generateProblem();
    xD = ap.operands[0];
    yD = ap.operands[1];
    Assert.isTrue( ap.type.numberRanges[1].lb <= xD &&
      xD <= ap.type.numberRanges[1].ub, "xD = "+ xD +" should be in number range.");
    Assert.isTrue( ap.type.numberRanges[2].lb <= yD &&
      yD <= ap.type.numberRanges[2].ub, "yD = "+ yD +" should be in number range.");
    Assert.areSame( ap.result, xD / yD);      
  },
  testTimesDividedBy: function () {
    var Assert = YAHOO.util.Assert;
    var ap = this.timesDividedBy.generateProblem();
    Assert.isTrue( ap.type.numberRanges[1].lb <= ap.operands[0] &&
      ap.operands[0] <= ap.type.numberRanges[1].ub, "Value should be in number range.");
    Assert.isTrue( ap.type.numberRanges[2].lb <= ap.operands[1] &&
      ap.operands[1] <= ap.type.numberRanges[2].ub, "Value should be in number range.");
    Assert.isTrue( ap.type.numberRanges[3].lb <= ap.operands[2] &&
      ap.operands[2] <= ap.type.numberRanges[3].ub, "Value should be in number range.");
    Assert.areSame( ap.result, ap.operands[0] * ap.operands[1] / ap.operands[2]);
  },
  testDivision200: function () {
    var Assert = YAHOO.util.Assert;
    var ap = null;
    for (var i=1; i<10; i++) {
      ap = this.division200.generateProblem();
      Assert.isTrue( ap.type.numberRanges[0].lb <= ap.result &&
        ap.result <= ap.type.numberRanges[0].ub, "Result value should be in first number range.");
      Assert.isTrue( ap.type.numberRanges[1].lb <= ap.operands[0] &&
        ap.operands[0] <= ap.type.numberRanges[1].ub, "Value should be in number range.");
      Assert.isTrue( ap.type.numberRanges[2].lb <= ap.operands[1] &&
        ap.operands[1] <= ap.type.numberRanges[2].ub, "Value should be in number range.");
      Assert.areSame( ap.result, ap.operands[0] / ap.operands[1]);
    }
  }
});
